package basic

import java.io.File

import scala.io.Source

/**
 * @className WordCount
 * @author sjw
 * @date 2020/11/19 13:45
 * @description: TODO
 */
object WordCount {

  def main(args: Array[String]): Unit = {
    val dirFile=new File("G:\\SparkData\\WordCount")
    val files=dirFile.listFiles()
    for(file<-files) println(file)

    val listFile=files.toList
    var wordsMap= scala.collection.mutable.Map[String,Int]()
    listFile.foreach(file=>{
       Source.fromFile(file).getLines().foreach(line=>line.split("").foreach(word=>{
         if(wordsMap.contains(word)){
           wordsMap(word)+=1
         }else{
           wordsMap+=(word->1)
         }
       }))
    })
    println(wordsMap)
    for((key,value)<-wordsMap) println(key+": "+value)

//    Source.fromFile("G:\\wordcount\\1.txt").foreach{
//      print
//    }
  }

}
